package com.sanrenzu.chunbo.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sanrenzu.chunbo.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by My on 2016/9/1.
 */
public class ShangPinAdapter extends PagerAdapter {

    private List<String> list = new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;

    public ShangPinAdapter(Context context, List<String> list){
        this.context=context;
        this.list =list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return list.size();
    }
    @Override

    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = inflater.inflate(R.layout.adapter_lunbo,container,false);

        ImageView lunbo_image_adapter_fragment = (ImageView) view.findViewById(R.id.lunbo_image_adapter_fragment);

        Glide.with(context).load(list.get(position)).into(lunbo_image_adapter_fragment);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }

}
